from django.db import models

# Create your models here.
# 创建表的模型对表的操作是直接修改这个文件，最终通过ORM模型映射到数据库中


# 书的作者表
class Author(models.Model):
    # 作者的名称
    name = models.CharField(max_length=20, verbose_name='作者名称')
    # 作者年龄
    age = models.IntegerField(verbose_name='年龄')
    # 作者邮箱
    email = models.EmailField(verbose_name='邮箱')
    # 性别选择
    choices = (('male', '男'), ('female', '女'))
    gender = models.CharField(default='male',
                              max_length=6,
                              choices=choices,
                              verbose_name='性别')


# 书籍表
class Book(models.Model):
    title = models.CharField(max_length=100, verbose_name='书名')
    price = models.DecimalField(max_digits=10, decimal_places=1, verbose_name='价格')
    # 外键
    Author = models.ForeignKey(Author, on_delete=models.CASCADE, verbose_name='作者')


# 个人信息表
class Person(models.Model):
    name = models.CharField(max_length=100, verbose_name='名字')
    age = models.IntegerField(verbose_name='年龄')
    gender = models.CharField(max_length=100, verbose_name='性别')
    city = models.CharField(max_length=100, verbose_name='城市')


# 扩展个人信息表
class ExtendInfo(models.Model):
    person = models.OneToOneField(to=Person, on_delete=models.CASCADE)
    love = models.CharField(max_length=100, verbose_name='爱好')
    marriage = models.BooleanField(default=False, verbose_name='婚姻状况')
    bloodType = models.CharField(max_length=100, verbose_name='血型')


# 课程表
class Course(models.Model):
    name = models.CharField(max_length=100, verbose_name='课程名称')
    lesson_number = models.IntegerField(verbose_name='课程数量')
    lecturer = models.CharField(max_length=100, verbose_name='讲师')


# 学生表
class Student(models.Model):
    course = models.ManyToManyField(to=Course)
    name = models.CharField(max_length=100, verbose_name='名字')
    age = models.IntegerField(verbose_name='年龄')
    gender = models.CharField(max_length=100, verbose_name='性别')
